package com.example.common;

import com.example.entity.Tuser;
import com.example.entity.User;
import com.example.service.TuserService;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 拦截器
 */
public class AuthInterceptor implements HandlerInterceptor {

    @Resource
    private TuserService tuserService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        String servletPath = request.getServletPath();
        Tuser tuser = (Tuser) request.getSession().getAttribute("tuser");
        if (tuser == null) {
            response.sendRedirect("/login.html");
            return false;
        }

        return true;
    }
//    @Override
//    public boolean preHandle1(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
//        String servletPath = request.getServletPath();
//        User user = (User) request.getSession().getAttribute("user");
//        if (user == null) {
//            response.sendRedirect("/login1.html");
//            return false;
//        }
//
//        return true;
//    }

}
